const express=require('express');
const db=require('../utils/db.js');

const router=express.Router();

router.post('/selidloction',(req,res)=>{
	const sql=`SELECT * FROM location WHERE id='${req.body.locationid}';`
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send(data)
		}
	})
})

router.post('/delectaddress',(req,res)=>{
	const sql=`DELETE FROM location where id=${req.body.locationid};`;
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send({msg:'删除成功'})
		}
	})
})

router.post('/editaddress',(req,res)=>{
// 	UPDATE location set name='李小花',phone='1324262542',address='上海黄浦区臧南路',houseNum='3号',label='学校',sex='女士' where id=7;
	const sql=`UPDATE location set name='${req.body.username}',phone='${req.body.phone}',address='${req.body.address}',houseNum='${req.body.houseNum}',label='${req.body.label}',sex='${req.body.sex}' where id='${req.body.locationid}';`
	// const sql=`UPDATE location set name=${req.body.username} where id=${req.body.locationid};`
	db.query(sql,(err,data)=>{
		if(err){
			res.send({msg:err})
		}else{
			res.send({msg:'修改成功'})
		}
	})
})

module.exports=router;